package com.offcn.dao.Impl;

import com.offcn.dao.BaseDao;
import com.offcn.dao.PageDao;
import com.offcn.entity.Course;
import com.offcn.utils.PageTool;

import java.util.List;

public class PageDaoImpl extends BaseDao<Course> implements PageDao {
    @Override
    public int getTotalCount(int courseType, String search) {
        String sql = "select count(*) from course where 1=1";
        if (courseType != 0) {
            sql += " and courseType = " + courseType;
        }
        if (null != search && !"".equals(search)) {
            sql += " and courseName like '%" + search + "%'";
        }
        long l = (long) singleData(sql);
        return (int) l;
    }

    @Override
    public List<Course> findByCourseType(int courseType, PageTool pageTool, String search) {
        String sql = "select * from course where 1=1";
        if (courseType != 0) {
            sql += " and courseType = " + courseType;
        }
        if (null != search && !"".equals(search)) {
            sql += " and courseName like '%" + search + "%'";
        }
        sql += " limit ?,?";
        return moreLine(sql, Course.class, pageTool.getStartIndex(), pageTool.getPageSize());
    }
}
